﻿/////const //////////////////////////

/////define object  /////////////////////////////////
try
{
    document.writeln("<OBJECT classid=\"clsid:FCAA4851-9E71-4BFE-8E55-212B5373F040\" height=1 id=bjcactrl  style=\"HEIGHT: 1px; LEFT: 10px; TOP: 28px; WIDTH: 1px\" width=1 VIEWASTEXT>");
    document.writeln("</OBJECT>");
    bjcactrl.GetUserListPnp();	 
}
catch(e)
{
	alert("CA驱动未能加载。请安装驱动，并用IE加载!");
}


/////组件接口转换为脚本接口////////////////////////
var g_xmluserlist;

//得到用户列表
function GetUserList() {

     try
     {
	    g_xmluserlist = bjcactrl.GetUserList();
     }
     catch(e)
     {
	    g_xmluserlist="";
	    alert(e.message);
    	
     }
	    return g_xmluserlist;
	    
}

//得到用户信息
function GetCertBasicinfo(Cert, Type) 
{

	return bjcactrl.GetCertInfo(Cert,Type);
	
}
function GetExtCertInfoByOID(Cert, oid) 
{
    
    return bjcactrl.GetCertInfoByOid(Cert,oid);
}

//登录
function Login(strFormName,strContainerName,strPin) {
	var ret;
	var objForm = eval(strFormName);

	if (objForm == null) {
		alert("Form Error");
		return false;
	}
	if (strPin == null || strPin == "") {
		alert("请输入Key的保护口令");
		return false;
	}


    if(!bjcactrl.UserLogin(strContainerName,strPin))
    {
    	
    	var extLib = bjcactrl.GetUserInfo(strContainerName, 15);
    	
    	var remainTimes = bjcactrl.GetBjcaKeyParam(extLib , 8);
    	
        alert("登录失败,剩余密码重试次数：" + remainTimes);
    //    return false;
    }
    
    strClientSignedData = SignedData(strContainerName,strServerRan);
    //alert("strServerCert:"+strServerCert+"\n\nstrServerRan:"+strServerRan+"\n\nstrServerSignedData:"+strServerSignedData);
   // if(!VerifySignedData(strServerCert,strServerRan,strServerSignedData))
   // {
        
     //   alert("验证服务器端信息失败!");
       // return false;
   // }
    
    //objForm.UserSignedData.value = strClientSignedData;
//	var varCert =  GetSignCert(strContainerName);
//	objForm.UserCert.value =  varCert;
//	objForm.ContainerName.value = strContainerName;
    
    return true;
    
}

//根据证书惟一标识，获取Base64编码的证书字符串。指定获取加密（交换）证书。
function GetExchCert(strContainerName)
{  
    var UserCert = bjcactrl.ExportExChangeUserCert(strContainerName);
   
    return UserCert;
}

//签名证书
function GetSignCert(strContainerName)
{  
    var UserCert = bjcactrl.ExportUserCert(strContainerName);
   
    return UserCert;
}


function SignedData(sContainerName,sInData) 
{
	if (sContainerName != null)
		return bjcactrl.SignData(sContainerName,sInData);
	else
		return "";
}


function VerifySignedData(cert,indata,signvalue)
{
    return bjcactrl.VerifySignedData(cert,indata,signvalue);

}




function GenerateRandom(RandomLen) 
{

	return bjcactrl.GenRandom(RandomLen);
}


//修改密码
function ChangeUserPassword(strContainerName,oldPwd,newPwd)
{	
	return bjcactrl.ChangePasswd(strContainerName,oldPwd,newPwd);
}

